<?php
namespace app\forum\service;
/**
 * 边栏接口
 */
class SidebarService{
	/**
	 * 获取边栏模块
	 */
	public function getForumSidebar(){
        $where = array();
        $userCount = target('forum/User')->countList($where);
        $where = array();
        $where['A.status'] = 1;
        $threadCount = target('forum/Thread')->countList($where);
        $where = array();
        $replyCount = target('forum/Reply')->countList($where);
        $where = array();
        $where['A.status'] = 1;
        $userList = target('forum/User')->loadList($where);
        $userHtml = '';
        foreach ($userList as $key => $value) {
            $userHtml.= '<li><a href="'.url('forum/UserHome/index',array('user_id'=>$value['user_id'])).'" title="'.$value['username'].'"><img class="avatar" width="64" height="64" src="'.target('forum/User')->avatar($value['user_id']).'" alt="'.$value['username'].'"></a></li>';
        }
        $where = array();
        $where['A.status'] = 1;
        $newsList = target('forum/Thread')->loadList($where);
        $newsHtml = '';
        if(!empty($newsList)){
            foreach ($newsList as $key => $value) {
                $newsHtml.= '<li><a href="'.$value['aurl'].'">'.$value['title'].'</a></li>';
            }
        }
		return array(
            'run' => array(
                'name' => '运行状况',
                'content' => '<div class="padding-small">
                        <table class="table table-noborder text-small">
                            <tbody>
                                <tr>
                                    <td width="80" align="right">注册会员</td>
                                    <td>'.$userCount.'</td>
                                </tr>
                                <tr>
                                    <td align="right">主题</td>
                                    <td>'.$threadCount.'</td>
                                </tr>
                                <tr>
                                    <td align="right">回复</td>
                                    <td>'.$replyCount.'</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>',
            ),
            'userList' => array(
                'name' => '新用户',
                'content' => '<ul class="user-list clearfix">
                        '.$userHtml.'
                    </ul>',
            ),
            'newsList' => array(
                'name' => '新主题',
                'content' => '<ul class="list-group">
                        '.$newsHtml.'
                    </ul>',
            ),
        );
	}
	


}
